<?php
class ControllerCommonCombobox extends Controller
{
	public function comboboxCategory()
	{
		$this->load->model("core/sitemap");
		$select = $this->request->get['select'];
		$index = $this->request->get['index'];
		$this->data['output'] = '<select name="category['.$index.']" onChange="selectCategory(this.value,\'\','.$index.')">';
		$this->data['output'].=	'<option value="" selected>Select</option>';
		$list = array();
		$this->model_core_sitemap->getTree("category", $list);
		foreach($list as $item)
		{
			
			$sel = '';
			if($select == $item['sitemapid'])
				$sel = 'selected="selected"';
			$this->data['output'].=	'<option value="'.$item['sitemapid'].'" '.$sel.'>'.$item['prefix'].$item['sitemapname'].'</option>';
		}
		$this->data['output'].=	'</select>';
		$this->id="content";
		$this->template="common/output.tpl";
		$this->render();
	}
	
	public function comboboxService()
	{
		$this->load->model("core/sitemap");
		$select = $this->request->get['select'];
		$index = $this->request->get['index'];
		$this->data['output'] = '<select name="category['.$index.']" onChange="selectCategory(this.value,\'\','.$index.')">';
		$this->data['output'].=	'<option value="" selected>Select</option>';
		$list = array();
		$this->model_core_sitemap->getTree("service", $list);
		foreach($list as $item)
		{
			
			$sel = '';
			if($select == $item['sitemapid'])
				$sel = 'selected="selected"';
			$this->data['output'].=	'<option value="'.$item['sitemapid'].'" '.$sel.'>'.$item['prefix'].$item['sitemapname'].'</option>';
		}
		$this->data['output'].=	'</select>';
		$this->id="content";
		$this->template="common/output.tpl";
		$this->render();
	}
	
	public function comboboxProduct()
	{
		$this->load->model("core/media");
		$category = $this->request->get['categoryid'];
		$select = $this->request->get['select'];
		
		$index = $this->request->get['index'];
		$this->data['output'] = '<select id="product'.$index.'" name="product['.$index.']" onChange="getPrice(this.value,'.$index.')">';
		$this->data['output'].=	'<option value="">Select</option>';
		$where = " AND refersitemap = '".$category."'";
		$list = $this->model_core_media->getList($where);
		foreach($list as $item)
		{
			$sel = '';
			if($select == $item['mediaid'])
				$sel = 'selected="selected"';
			$this->data['output'].=	'<option value="'.$item['mediaid'].'" '.$sel.'>'. htmlspecialchars( $item['title'].' ('.$item['unit'].')').'</option>';
		}
		$this->data['output'].=	'</select>';
		$this->id="content";
		$this->template="common/output.tpl";
		$this->render();
	}
	
	public function comboboxDoctor()
	{
		$this->load->model("core/user");
		$select = $this->request->get['select'];
		$where = " AND usertypeid = 'doctor' ";
		$doctors = $this->model_core_user->getList($where);
		$this->data['output']="<option value=''>Select</option>";
		foreach($doctors as $item)
		{
			$sel = '';
			if($select == $item['userid'])
				$sel = 'selected="selected"';
			$this->data['output'].=	'<option value="'.$item['userid'].'" '.$sel.'>'.$item['fullname'].'</option>';
		}
		$this->id="content";
		$this->template="common/output.tpl";
		$this->render();
	}
	
	public function getItem()
	{
		$this->load->model("core/media");
		$mediaid = $this->request->get['mediaid'];
		$item=$this->model_core_media->getItem($mediaid);
		$this->data['output'] = json_encode(array('item' => $item));
		$this->id='post';
		$this->template="common/output.tpl";
		$this->render();
	}
}
?>